package jpsearchcore;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import jpsearchcore.RegionOfInterestType.ContentDescription;

public class RegionOfInterest {

	private RegionLocator regionLocator = new RegionLocator();
	private String Description = null;
	private List<String> Keywords = new ArrayList<String>();
	private String Title = null;
	private ContentDesciption contentDescription = new ContentDesciption();
	private List<ExternalDescription> externalDescription = new ArrayList<ExternalDescription>();

	public RegionOfInterest(RegionOfInterestType r){

		//RegionLocator
		List<IntegerMatrixType> gMatrixType = r.getRegionLocator().getRegion();
		regionLocator = new RegionLocator(gMatrixType);

		//Description
		try{
			Description = r.getDescription().trim();
		}catch(NullPointerException e){}

		//Keywords
		try{
			for(String s : r.getKeyword()){
				if(!StringUtils.isBlank(s))
					Keywords.add(s.trim());
			}
		}catch(NullPointerException e){}

		//Title
		try{
			Title = r.getTitle().trim();
		}catch(NullPointerException e){}

		//ContentDescription
		ContentDescription cd = r.getContentDescription();
		if(cd != null)
			contentDescription = new ContentDesciption(cd);	

		//External Description
		List<ExternalDescriptonType> edt = r.getExternalDescription();
		for(ExternalDescriptonType ed : edt){
			externalDescription.add(new ExternalDescription(ed));
		}

	}

	public RegionOfInterest(){}

	public RegionOfInterest(RegionOfInterest roi){
		regionLocator = roi.getRegionLocator();
		Description = roi.getDescription();
		Keywords = roi.getKeywords();
		Title = roi.getTitle();
		contentDescription = roi.getContentDescription();
		externalDescription = roi.getExternalDescription();
	}

	public RegionOfInterest(RegionLocator regionLocator, String description,
			List<String> keywords, String title,
			ContentDesciption contentDescription,
			List<ExternalDescription> externalDescription) {
		this.regionLocator = regionLocator;
		Description = description;
		Keywords = keywords;
		Title = title;
		this.contentDescription = contentDescription;
		this.externalDescription = externalDescription;
	}

	public RegionLocator getRegionLocator() {
		return regionLocator;
	}

	public String getDescription() {
		return Description;
	}

	public List<String> getKeywords() {
		return Keywords;
	}

	public String getTitle() {
		return Title;
	}

	public ContentDesciption getContentDescription() {
		return contentDescription;
	}

	public List<ExternalDescription> getExternalDescription() {
		return externalDescription;
	}


	public void setRegionLocator(RegionLocator regionLocator) {
		this.regionLocator = regionLocator;
	}


	public void setDescription(String description) {
		Description = description;
	}


	public void setKeywords(List<String> keywords) {
		Keywords.addAll(keywords);
	}


	public void setTitle(String title) {
		Title = title;
	}


	public void setContentDescription(ContentDesciption contentDescription) {
		this.contentDescription = contentDescription;
	}


	public void setExternalDescription(List<ExternalDescription> externalDescription) {
		this.externalDescription = externalDescription;
	}


	public String toString(){
		String output = "RegionOfInterest: [\n\tRegionLocator: ";
		output += regionLocator;
		output += "\n\tDescription: " + Description;
		output += "\n\tKeywords: " + Keywords;
		output += "\n\tTitle: " + Title ;
		output += "\n\tContentDescription: " + contentDescription;
		output += "\n\tExternalDescription: " + externalDescription;
		output += "\n]";
		return output;
	}
}
